package com.example.hello;

import com.vaadin.shared.MouseEventDetails;
import com.vaadin.ui.AbstractComponent;

/**
 * CBW: Write me.
 *
 * @author Chris Wash <a href="mailto:chris.wash@gmail.com">chris.wash@gmail.com</a>
 */
public class BootstrapButton extends AbstractComponent {

    private BootstrapButtonRpc rpc = new BootstrapButtonRpc() {

        public void click(MouseEventDetails details) {

            fireEvent(new BootstrapClickEvent(BootstrapButton.this));
        }
    };

    public enum Size {

        LARGE, DEFAULT, SMALL, MINI;
    }

    public enum Type {

        DEFAULT, PRIMARY, INFO, SUCCESS, WARNING, DANGER, INVERSE;
    }

    public BootstrapButton() {

        this("", Type.DEFAULT, Size.DEFAULT);
    }

    public BootstrapButton(String caption, Size size) {

        this(caption, Type.DEFAULT, size);
    }

    public BootstrapButton(String caption, Type type) {

        this(caption, type, Size.DEFAULT);
    }

    public BootstrapButton(String caption, Type type, Size size) {

        setText(caption);
        setSize(size);
        setType(type);

        setImmediate(true);

        registerRpc(rpc);
    }

    public BootstrapButton(String caption) {

        this(caption, Size.DEFAULT);
    }

    public BootstrapButton(Size size) {

        this("", size);
    }

    public BootstrapButton(Type type) {

        this("", type);
    }

    public Size getSize() {

        return Size.valueOf(getState().getSize());
    }

    public Type getType() {

        return Type.valueOf(getState().getType());
    }

    @Override
    public BootstrapButtonState getState() {

        return (BootstrapButtonState) super.getState();
    }

    public String getText() {

        return getState().getText();
    }

    public void setSize(Size size) {

        getState().setSize(size.toString());

        requestRepaint();
    }

    public void setType(Type size) {

        getState().setType(size.toString());

        requestRepaint();
    }

    public void setText(String text) {

        getState().setText(text);

        requestRepaint();
    }

}
